package com.fsgom.common.web.view;

import java.util.Locale;

import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import com.fsgom.common.web.layout.LayoutHolder;

public class LayoutViewResolver extends UrlBasedViewResolver {
	public LayoutViewResolver() {
		setViewClass(requiredViewClass()); // NOPMD
	}

	@Override
	protected Class<?> requiredViewClass() {
		return LayoutView.class;
	}

	@Override
	protected View createView(String viewName, Locale locale) throws Exception {
		if (LayoutHolder.layout() == null || !viewName.startsWith(LayoutView.LAYOUT_URL_PREFIX)) {
			return null;
		}

		return new LayoutView(viewName, getPrefix(), getSuffix());
	}
}
